package gene.android.accountingpro.equations;

import gene.android.accountingpro.finals.EquationNames;
import gene.android.accountingpro.finals.FieldList;

import java.util.ArrayList;
import java.util.List;

public class EarningsPerShare extends Equation{
	
	private double income_available_to_common;
	private double weighted_average_number_of_common_shares;
	
	public EarningsPerShare(){}
	
	public EarningsPerShare( double incomeAvailableToCommon, double weightedAverageNumberOfCommonShares ){
		
		this.income_available_to_common = incomeAvailableToCommon;
		this.weighted_average_number_of_common_shares = weightedAverageNumberOfCommonShares;
		value = ( income_available_to_common / weighted_average_number_of_common_shares );
	}
	
	@Override
	public String getEquationName() {
		return EquationNames.EARNINGS_PER_SHARE;
	}

	@Override
	public List<String> getRequiredFields() {
		List<String> requiredFields = new ArrayList<String>();
		requiredFields.add(FieldList.INCOME_AVAILABLE_TO_COMMON);
		requiredFields.add(FieldList.WEIGHTED_AVERAGE_NUMBER_OF_COMMON_SHARES);
		return requiredFields;
	}

	@Override
	public void setValues(double[] values) {
		income_available_to_common = values[0];
		weighted_average_number_of_common_shares = values[1];
		solve();
	}

	@Override
	public String getSolvedEquationString() {
		return "( " + income_available_to_common +" / " + weighted_average_number_of_common_shares +" ) = " +value;
	}

	@Override
	public String getEquationString() {
		return "( " + FieldList.INCOME_AVAILABLE_TO_COMMON +" / " + FieldList.WEIGHTED_AVERAGE_NUMBER_OF_COMMON_SHARES +" )";
	}

	@Override
	public void solve() {
		value = ( income_available_to_common / weighted_average_number_of_common_shares );
	}

}
